/// created by hcl
/// on 2025/5/9
/// NoteDetailModel
/// desc
class NoteDetailModel {
  String title = '';
  String content = '';
  String createTime = '';
  int updateTime = 0;
  TextType type = TextType.text;

  NoteDetailModel(
    this.title,
    this.content,
    this.createTime,
    this.updateTime,
    this.type,
  );

  NoteDetailModel.fromMap(Map<String, dynamic> map) {
    title = map['title'] ?? '';
    content = map['content'] ?? '';
    createTime = map['createTime'] ?? '';
    updateTime = map['updateTime'] ?? 0;
    type = TextType.parseType(map['type'] ?? 0);
  }

  Map<String, dynamic> toMap() {
    Map<String, dynamic> map = {};
    map['title'] = title;
    map['content'] = content;
    map['createTime'] = createTime;
    map['updateTime'] = updateTime;
    map['type'] = type.index;
    return map;
  }

  NoteDetailModel copyWith({
    String? title,
    String? content,
    String? createTime,
    int? updateTime,
    TextType? type,
  }) {
    return NoteDetailModel(
      title ?? this.title,
      content ?? this.content,
      createTime ?? this.createTime,
      updateTime ?? this.updateTime,
      type ?? this.type,
    );
  }

  @override
  String toString() {
    return toMap().toString();
  }
}

enum TextType {
  /// 文本类型
  text,

  /// 图片类型
  image,

  /// 视频类型
  video;

  static TextType parseType(int index) {
    return TextType.values[index];
  }
}
